package DesignPatern.A10_责任链模式.QSB.A02_责任链模式;

/**
 * @Author: Du
 * @Date: 2021/7/28 9:31
 */
public abstract class Handler
{
    public final static int FATHER_LEVEL_REQUEST = 1;
    public final static int HUSBAND_LEVEL_REQUEST = 2;
    public final static int SON_LEVEL_REQUEST = 3;
    
    private int level = 0;
    
    private Handler nextHandler;
    
    public Handler(int level)
    {
        this.level = level;
    }
    
    //责任链模式关键方法
    public final void HandleMessage(IWomen women)
    {
        if (women.getType() == this.level)
        {
            this.response(women);
        } else
        {
            if (this.nextHandler != null)
            {
                this.nextHandler.HandleMessage(women);
            } else
            {
                System.out.println("--没有地方请示，按不同意处理--");
            }
        }
    }
    
    public void setNext(Handler handler)
    {
        this.nextHandler = handler;
    }
    
    protected abstract void response(IWomen women);
}
